package io.qar;

import org.quartz.*;

import java.time.LocalDateTime;

/**
 * @program: qar-cloud
 * @description:
 * @author: yyyyjinying
 * @create: 2023-09-28 09:41
 * 任务组件需要实现的接口
 * 表明需要完成什么类型的任务
 **/
public class HelloJob implements Job {
//    状态
    @Override
    public void execute(JobExecutionContext context) throws JobExecutionException {
        Object tv1 = context.getTrigger().getJobDataMap().get("t1");
        Object tv2 = context.getTrigger().getJobDataMap().get("t2");
        // 从jobDataMap中获取数据
        // JobDataMap存储的对象会被序列化，可能会导致类的版本不一致的问题
        JobDataMap jobDataMap = context.getJobDetail().getJobDataMap();
        String j1 = jobDataMap.getString("j1");
        String j2 = jobDataMap.getString("j2");
        JobDataMap jobDataMap1 = context.getTrigger().getJobDataMap();
        String t1 = jobDataMap1.getString("t1");
        String t2 = jobDataMap1.getString("t2");
        TriggerKey triggerKey = context.getTrigger().getKey();
        JobKey jobKey = context.getTrigger().getJobKey();

        System.out.println("j1=>" + j1);
        System.out.println("j2=>" + j2);
        System.out.println("t1=>" + t1);
        System.out.println("t2=>" + t2);

        JobKey key = context.getJobDetail().getKey();
        // jobkey: mygroup.myjob
        System.out.println("jobkey: " + key);
        // triggerKey: group1.trigger1
        System.out.println("triggerKey: " + triggerKey);
        System.out.println("jobKey: " + jobKey);

        // 将 job的JobDataMap和trigger的JobDataMap合并获取
        JobDataMap mergedJobDataMap = context.getMergedJobDataMap();
        String t11 = mergedJobDataMap.getString("t1");
        String j11 = mergedJobDataMap.getString("j1");
        System.out.println("t11: " + t11);
        System.out.println("j11: " + j11);

        context.setResult("fdf");
    }
}

